﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SimpleTaskSystem
{
    public class OperationMessage : MonoBehaviour
    {
        public static OperationMessage Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = FindObjectOfType<OperationMessage>();
                }
                return instance;
            }
        }
        static OperationMessage instance;
        public Dictionary<string, Operation> operationDic = new Dictionary<string, Operation>();
        //public static Operation.OperationHandler oneOperationCompleted;

        public static void AddOperation(Operation operation)
        {
            if (!Instance.operationDic.ContainsKey(operation.operationName))
            {
                Instance.operationDic.Add(operation.operationName, operation);
            }
        }
        public static void OperationCompleted(string operationName)
        {
            if (operationName != string.Empty && Instance.operationDic.ContainsKey(operationName))
            {
                Debug.Log(operationName);
                Instance.operationDic[operationName].OnCompleted();
            }
            //if (oneOperationCompleted != null)
            //{
            //    oneOperationCompleted(operationDic[operationName]);
            //}
        }

        public void SendOperationMessage(string operationName)
        {
            OperationCompleted(operationName);
        }

    }
}
